﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Webdiyer.WebControls.Mvc;
using Zor_Bll;
using Zor_Modes;
using Zor_Tools;
using Zor_Web.Models;
using Zor_Web.Models.Browse;
using Zor_Web.Models.Stat;

namespace Zor_Web.Controllers
{
    [Authorization]
    public class StatController : Controller
    {

        #region - 出租房屋表 -
        /// <summary>
        /// 出租房屋表
        /// create by Guoph at 2017.3.27
        /// </summary>
        /// <param name="index"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public ActionResult Zor_LeaseHous(Models.Stat.V_Zor_LeaseHous model, int? index = 1, string where = null)
        {

            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_Zor_LeaseHous> zvPager = Zor_LeaseHous_Bll<V_Zor_LeaseHous>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_Zor_LeaseHous>;

            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);

            V_Zor_LeaseHous vb = new V_Zor_LeaseHous();
            vb.PageData = zvPager;
            return View(vb);
        }

        /// <summary>
        /// 导出出租房屋表
        /// create light by 17.4.12
        /// </summary>
        /// <param name="fields">要导出的列表字段集合</param>
        /// <returns>返回数据流</returns>
        [HttpPost]
        public FileResult ExportLeaseHous(FormCollection form)
        {
            string fields = form["fields"];
            string where = form["where"];
            string[] str_arr = fields.Split(',');
            NoSortHashTable nameList = new NoSortHashTable();

            for (int i = 0; i < str_arr.Length; i++)
            {
                if (str_arr[i] != "")
                {
                    string[] item = str_arr[i].Split('|');
                    nameList.Add(item[0], item[1]);
                }
            }

            #region 拼接table

            System.Text.StringBuilder data = new System.Text.StringBuilder();
            if (nameList != null)
            {
                data.Append("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\">");
                //写出列名
                data.Append("<tr style=\"font-weight: bold; white-space: nowrap;\">");


                foreach (string s in nameList.Keys)
                {
                    data.Append("<td>" + nameList[s] + "</td>");
                }
                data.Append("</tr>");

                List<V_Zor_LeaseHous> list = Zor_LeaseHous_Bll<V_Zor_LeaseHous>.GetList(where);
                //写出数据
                foreach (V_Zor_LeaseHous model in list)
                {
                    data.Append("<tr>");
                    foreach (string sm in nameList.Keys)
                    {
                        switch (sm)
                        {
                            case "Bd_Name": data.Append("<td>" + model.Bd_Name + "</td>"); break;
                            case "Uim_Name": data.Append("<td>" + model.Uim_Name + "</td>"); break;
                            case "Hs_Number": data.Append("<td>" + model.Hs_Number + "</td>"); break;
                            case "Hs_Proportion": data.Append("<td>" + model.Hs_Proportion + "</td>"); break;
                            case "NatPer_Name": data.Append("<td>" + model.NatPer_Name + "</td>"); break;
                            case "NatPer_Phone": data.Append("<td>" + model.NatPer_Phone + "</td>"); break;
                            case "TenantType": data.Append("<td>" + model.TenantType + "</td>"); break;
                            case "Tenant_Name": data.Append("<td>" + model.Tenant_Name + "</td>"); break;
                            case "Lease_Rent": data.Append("<td>" + model.Lease_Rent + "</td>"); break;
                            case "Lease_CreateTime": data.Append("<td>" + model.Lease_CreateTime + "</td>"); break;
                            case "Lease_EndTime": data.Append("<td>" + model.Lease_EndTime + "</td>"); break;
                        }
                    }
                    data.Append("</tr>");
                }
                data.Append("</table>");
            }
            #endregion


            string sw = ExcelHelper.ExcelTemplate(data.ToString());

            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
            // 写入到数据流
            return File(System.Text.Encoding.UTF8.GetBytes(sw.ToString()), "application/octet-stream", "出租房屋表清单_" + fileName + ".xls");

        }
        #endregion

        #region - 缴税统计表 -

        /// <summary>
        /// 缴税统计表
        /// create by light at 2017.4.13
        /// </summary>
        /// <param name="index"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public ActionResult TaxStat(Models.Stat.V_TaxStat model, int? index = 1, string where = null)
        {

            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_TaxStat> zvPager = TaxStat_Bll<V_TaxStat>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_TaxStat>;

            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);

            V_TaxStat vb = new V_TaxStat();
            vb.PageData = zvPager;
            return View(vb);
        }
        /// <summary>
        /// 导出缴税统计表
        /// create light by 17.4.12
        /// </summary>
        /// <param name="fields">要导出的列表字段集合</param>
        /// <returns>返回数据流</returns>
        [HttpPost]
        public FileResult ExportTaxStat(FormCollection form)
        {
            string fields = form["fields"];
            string where = form["where"];
            string[] str_arr = fields.Split(',');
            NoSortHashTable nameList = new NoSortHashTable();

            for (int i = 0; i < str_arr.Length; i++)
            {
                if (str_arr[i] != "")
                {
                    string[] item = str_arr[i].Split('|');
                    nameList.Add(item[0], item[1]);
                }
            }

            #region 拼接table

            System.Text.StringBuilder data = new System.Text.StringBuilder();
            if (nameList != null)
            {
                data.Append("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\">");
                //写出列名
                data.Append("<tr style=\"font-weight: bold; white-space: nowrap;\">");


                foreach (string s in nameList.Keys)
                {
                    data.Append("<td>" + nameList[s] + "</td>");
                }
                data.Append("</tr>");

                List<V_TaxStat> list = TaxStat_Bll<V_TaxStat>.GetList(where);
                //写出数据
                foreach (V_TaxStat model in list)
                {
                    data.Append("<tr>");
                    foreach (string sm in nameList.Keys)
                    {
                        switch (sm)
                        {
                            case "Housename": data.Append("<td>" + model.Housename + "</td>"); break;
                            case "Statue": data.Append("<td>" + model.Statue + "</td>"); break;
                            case "PtState": data.Append("<td>" + model.PtState + "</td>"); break;
                            case "Pt_ActualTax": data.Append("<td>" + model.Pt_ActualTax + "</td>"); break;
                        }
                    }
                    data.Append("</tr>");
                }
                data.Append("</table>");
            }
            #endregion
            string sw = ExcelHelper.ExcelTemplate(data.ToString());

            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
            // 写入到数据流
            return File(System.Text.Encoding.UTF8.GetBytes(sw.ToString()), "application/octet-stream", "缴税统计表清单_" + fileName + ".xls");

        }
        #endregion

        #region - 年度税收统计图表 -

        /// <summary>
        /// 年度税收统计图表     
        /// <summary>
        /// 税收统计表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="where"></param>
        public ActionResult AnnualTaxChart(int? index = 1, string where = null)
        {
            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_AnnualTaxChart> zvPager = AnnualTaxChart_Bll<V_AnnualTaxChart>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_AnnualTaxChart>;
            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);
            V_AnnualTaxChart vb = new V_AnnualTaxChart();
            vb.PageData = zvPager;
            return View(vb);
        }

        /// <summary>
        /// 年度税收统计饼状图
        /// </summary>
        /// <returns></returns>
        public ActionResult AnnualTax_Pie()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称、
            List<dynamic> lst = AnnualTaxChart_Bll<dynamic>.GetATList();
            //查询所有街道办的税收总计
            List<dynamic> lstSumTax = AnnualTaxChart_Bll<dynamic>.getSumAnnualTax();
            var sumtax = lstSumTax[0].SumXiaoji; //所有街办纳税总额
            sb.Append("[");
            string strData = "";//名称字符串
            foreach (var item in lst)
            {
                strData += "{value:" + item.xiaoji + ",name:'" + item.Dt_Name + "'},";
            }
            sb.Append(strData.TrimEnd(','));//去掉最后一个','逗号
            sb.Append("]");
            return Content(sb.ToString());
        }

        #endregion

        #region - 房屋登记统计图表 -
        /// <summary>
        /// 房屋登记统计图表     
        /// <summary>
        /// 税收统计表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="where"></param>
        public ActionResult HouseRegister(int? index = 1, string where = null)
        {

            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_HouseRegister> zvPager = HouseRegister_Bll<V_HouseRegister>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_HouseRegister>;
            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);
            V_HouseRegister vb = new V_HouseRegister();
            vb.PageData = zvPager;
            return View(vb);
        }
        
        /// <summary>
        ///房屋登记统计部门数据 
        /// </summary>
        /// <returns></returns>
        public ActionResult HouseRegisterName_Col()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegister_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string strSOName = "";//街道办名称字符串 
            foreach (var item in lst)
            {
                strSOName += "'" + item.Dt_Name + "',";
            }
            sb.Append(strSOName.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        ///房屋登记统计住宅数
        /// </summary>
        /// <returns></returns>
        public ActionResult HouseRegisterstrHouNumber_Col()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegister_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string strhouNumber = "";//住宅数字符串 
            foreach (var item in lst)
            {
                strhouNumber += "" + item.houNumber + ",";
            }
            sb.Append(strhouNumber.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        ///房屋登记统计非住宅数
        /// </summary>
        /// <returns></returns>
        public ActionResult HouseRegisterstrShopNumber_Col()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegister_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string strShopNumber = "";//住宅数字符串 
            foreach (var item in lst)
            {
                strShopNumber += "" + item.shopNumber + ",";
            }
            sb.Append(strShopNumber.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        ///房屋登记统计街办受理数
        /// </summary>
        /// <returns></returns>
        public ActionResult HouseRegisterstrShopANumber_Col()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegister_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string ANumber = "";//住宅数字符串 
            foreach (var item in lst)
            {
                ANumber += "" + item.ANumber + ",";
            }
            sb.Append(ANumber.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        #endregion

        #region - 税收统计表 -
        /// <summary>
        /// 税收统计表
        /// create by light at 2017.4.13
        /// </summary>
        /// <param name="index"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public ActionResult TaxRevenueStat(V_TaxRevenueStat Model, int? index = 1, string where = null)
        {
             int totalCount = 0;
            int pageIndex = index ?? 1;

            PagedList<V_TaxRevenueStat> zvPager = TaxRevenueStat_Bll<V_TaxRevenueStat>.GetPageList(Model, pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_TaxRevenueStat>;

            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);

            V_TaxRevenueStat vb = new V_TaxRevenueStat();
            vb.PageData = zvPager;
            return View(vb);
        }
         /// <summary>
        /// 导出税收统计表
        /// create light by 17.4.12
        /// </summary>
        /// <param name="fields">要导出的列表字段集合</param>
        /// <returns>返回数据流</returns>
        [HttpPost]
        public FileResult ExportTaxRevenueStat(FormCollection form)
        {
            string fields = form["fields"];
            string where = form["where"];
            string[] str_arr = fields.Split(',');
            NoSortHashTable nameList = new NoSortHashTable();

            for (int i = 0; i < str_arr.Length; i++)
            {
                if (str_arr[i] != "")
                {
                    string[] item = str_arr[i].Split('|');
                    nameList.Add(item[0], item[1]);
                }
            }

            #region 拼接table

            System.Text.StringBuilder data = new System.Text.StringBuilder();
            if (nameList != null)
            {
                data.Append("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\">");
                //写出列名
                data.Append("<tr style=\"font-weight: bold; white-space: nowrap;\">");


                foreach (string s in nameList.Keys)
                {
                    data.Append("<td>" + nameList[s] + "</td>");
                }
                data.Append("</tr>");

                List<V_TaxRevenueStat> list = TaxRevenueStat_Bll<V_TaxRevenueStat>.GetList(where);
                //写出数据
                foreach (V_TaxRevenueStat model in list)
                {
                    data.Append("<tr>");
                    foreach (string sm in nameList.Keys)
                    {
                        switch (sm)
                        {
                            case "Dt_Name": data.Append("<td>" + model.Dt_Name + "</td>"); break;
                            case "Jb": data.Append("<td>" + model.Jb + "</td>"); break;
                            case "Pt_ActualTax": data.Append("<td>" + model.Pt_ActualTax + "</td>"); break;
                        }

                    }
                    data.Append("</tr>");
                }
                data.Append("</table>");
            }
            #endregion
            string sw = ExcelHelper.ExcelTemplate(data.ToString());

            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
            // 写入到数据流
            return File(System.Text.Encoding.UTF8.GetBytes(sw.ToString()), "application/octet-stream", "税收统计表清单_" + fileName + ".xls");

        }
        #endregion

        #region - 房屋登记统计图表（街道办） -

        
        /// <summary>
        /// 房屋登记统计图表（街道办）     
        /// <summary>
        /// 税收统计表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="where"></param>
        public ActionResult HouseRegisterStreetOffice(int? index = 1, string where = null)
        {

            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_HouseRegisterStreetOffice> zvPager = HouseRegisterStreetOffice_Bll<V_HouseRegisterStreetOffice>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_HouseRegisterStreetOffice>;
            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);
            V_HouseRegisterStreetOffice vb = new V_HouseRegisterStreetOffice();
            vb.PageData = zvPager;
            return View(vb);
           
        }
       
        /// <summary>
        ///房屋登记统计部门数据 （社区）
        /// </summary>
        /// <returns></returns>
        public ActionResult GetCommunityName()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegisterStreetOffice_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string strSOName = "";//社区名称字符串 
            foreach (var item in lst)
            {
                strSOName += "'" + item.Dt_Name + "',";
            }
            sb.Append(strSOName.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        ///房屋登记统计住宅数（社区）
        /// </summary>
        /// <returns></returns>
        public ActionResult GetStreetOfficeHouNum()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegisterStreetOffice_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string strhouNumber = "";//住宅数字符串 
            foreach (var item in lst)
            {
                strhouNumber += "" + item.houNumber + ",";
            }
            sb.Append(strhouNumber.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        ///房屋登记统计非住宅数（社区）
        /// </summary>
        /// <returns></returns>
        public ActionResult GetStreetOfficeShopNum()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegisterStreetOffice_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string strShopNumber = "";//住宅数字符串 
            foreach (var item in lst)
            {
                strShopNumber += "" + item.shopNumber + ",";
            }
            sb.Append(strShopNumber.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        ///房屋登记统计街办受理数（社区）
        /// </summary>
        /// <returns></returns>
        public ActionResult GetStreetOfficeANum()
        {
            StringBuilder sb = new StringBuilder();
            //获取所有街道办名称及对应的值、
            List<dynamic> lst = HouseRegisterStreetOffice_Bll<dynamic>.GetHRList();
            sb.Append("[");
            string ANumber = "";//住宅数字符串 
            foreach (var item in lst)
            {
                ANumber += "" + item.ANumber + ",";
            }
            sb.Append(ANumber.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        
        #endregion

        #region - GIS年度税收 -
        public ActionResult AnnualTaskMap()
        {
            return View();
        }
        /// <summary>
        /// 获取街道办地图加载信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAnnualTaskInfo()
        {
            List<V_AnnualTaskMap> lst_AnnualTaskInfo = AnnualTaskMap_Bll<V_AnnualTaskMap>.GetAnnualTaskList();
            return Content(lst_AnnualTaskInfo.ToJson());
        }
        #endregion

        #region - 税收统计总览 -

        /// <summary>
        /// 显示税收统计总览
        /// create light by 2017.3.24
        /// </summary>
        /// <returns></returns>
        //public ActionResult TaxPandect()
  
        public ActionResult TaxPandect(int? index = 1, string where = null)
        {

            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_TaxRevenueStat> zvPager = TaxPandect_Bll<V_TaxRevenueStat>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_TaxRevenueStat>;
            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);
            V_TaxRevenueStat vb = new V_TaxRevenueStat();
            vb.PageData = zvPager;
            return View(vb);
        }

        static string Tax_Month = "";   //已收税年月
        /// <summary>
        ///税收统计总览小计
        /// </summary>
        /// <returns></returns>
        public ActionResult TaxPandectPt_ActualTax()
        {
            Tax_Month = "";
            StringBuilder sb = new StringBuilder();
            List<dynamic> lst = TaxPandect_Bll<dynamic>.GetTaxPandect();
            sb.Append("[");
            string Pt_ActualTax = "";
            foreach (var item in lst[0])
            {
                Pt_ActualTax += "'" + item.Value + "',";
                Tax_Month += "'" + item.Key + "',";
            }
            sb.Append(Pt_ActualTax.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }

        /// <summary>
        /// 税收统计总览年月
        /// </summary>
        /// <returns></returns>
        public ActionResult TaxPandect_Months()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("[");

            sb.Append(Tax_Month.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }

        #endregion

        #region - 出租税收统计 -

        /// <summary>
        /// 显示出租税收统计
        /// create light by 2017.3.24
        /// </summary>
        /// <returns></returns>
        //public ActionResult TaxPandect()

        public ActionResult LeaseTaxStat(int? index = 1, string where = null)
        {

            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_LeaseTaxStat> zvPager = LeaseTaxStat_Bll<V_LeaseTaxStat>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_LeaseTaxStat>;
            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);
            V_LeaseTaxStat vb = new V_LeaseTaxStat();
            vb.PageData = zvPager;
            return View(vb);
        }
        static string T_Month = "";   //已收税年月
        /// <summary>
        ///已收税户数
        /// </summary>
        /// <returns></returns>
        public ActionResult TaxHouseholds()
        {
            T_Month = "";
            StringBuilder sb = new StringBuilder();
            List<dynamic> lst = LeaseTaxStat_Bll<dynamic>.GetLeaseTaxStat();
            sb.Append("[");
            string TaxHouseholds = "";
            foreach (var item in lst[0])
            {
                TaxHouseholds += "'" + item.Value + "',";
                T_Month += "'" + item.Key + "',";
            }
            sb.Append(TaxHouseholds.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        /// 已收税年月
        /// </summary>
        /// <returns></returns>
        public ActionResult months()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("[");

            sb.Append(T_Month.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        static string str_month = "";   //已租年月
        /// <summary>
        ///已租户数
        /// </summary>
        /// <returns></returns>
        public ActionResult LeaseHouseholds()
        {
            str_month = "";
            StringBuilder sb = new StringBuilder();
            List<dynamic> lst = LeaseTaxStat_Bll<dynamic>.GetLeaseHouseholds();
            sb.Append("[");
            string LeaseHouseholds = "";
            foreach (var item in lst[0])
            {
                LeaseHouseholds += "'" + item.Value + "',";
                str_month += "'" + item.Key + "',";
            }
            sb.Append(LeaseHouseholds.TrimEnd(','));//去掉最后一个','逗号  
            sb.Append("]");
            return Content(sb.ToString());
        }
        /// <summary>
        /// 已租年月
        /// </summary>
        /// <returns></returns>
        public ActionResult L_month()
        {
           StringBuilder sb = new StringBuilder();
           sb.Append("[");
           sb.Append(str_month.TrimEnd(','));//去掉最后一个','逗号  
           sb.Append("]");
            return Content(sb.ToString());
        }

        #endregion

        #region - 预览总表 -

        /// <summary>
        /// 预览总表        
        /// </summary>
        /// <returns></returns>
        //public ActionResult TaxPandect()

        public ActionResult Preview(int? index = 1, string where = null)
        {
            int totalCount = 0;
            int pageIndex = index ?? 1;
            PagedList<V_Preview> zvPager = Preview_Bll<V_Preview>.GetPageList(pageIndex, out totalCount, where).AsQueryable().ToPagedList(0, 10) as PagedList<V_Preview>;
            zvPager.TotalItemCount = totalCount;
            zvPager.CurrentPageIndex = (int)(index ?? 1);
            V_Preview vb = new V_Preview();
            vb.PageData = zvPager;
            return View(vb);
        }
       /// <summary>
       /// 模态详情
       /// </summary>
       /// <param name="Bd_ID"></param>
       /// <returns></returns>
        public ActionResult LoadDetailInfoModal(int Bd_ID)
        {
            List<dynamic> lst_DetailInfo = Preview_Bll<dynamic>.DetailInfo(Bd_ID);
            return Content(lst_DetailInfo.ToJson());
        }
        
       
        /// <summary>
        /// 导出数据
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public FileResult PreviewMeg(FormCollection form)
        {
            string PreviewMeg = form["PreviewMeg"];
            string where = form["where"];
            string[] str_arr = PreviewMeg.Split(',');
            NoSortHashTable nameList = new NoSortHashTable();

            for (int i = 0; i < str_arr.Length; i++)
            {
                if (str_arr[i] != "")
                {
                    string[] item = str_arr[i].Split('|');
                    nameList.Add(item[0], item[1]);
                }
            }

            #region 拼接table

            System.Text.StringBuilder data = new System.Text.StringBuilder();
            if (nameList != null)
            {
                data.Append("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\">");
                //写出列名
                data.Append("<tr style=\"font-weight: bold; white-space: nowrap;\">");

                foreach (string s in nameList.Keys)
                {
                    data.Append("<td>" + nameList[s] + "</td>");
                }
                data.Append("</tr>");

                List<V_Preview> list = Preview_Bll<V_Preview>.GetList(where);
                //写出数据
                foreach (V_Preview model in list)
                {
                    data.Append("<tr>");
                    foreach (string sm in nameList.Keys)
                    {
                        switch (sm)
                        {
                            case "Dt_Name": data.Append("<td>" + model.Dt_Name + "</td>"); ; break;
                            case "Bd_Name": data.Append("<td>" + model.Bd_Name + "</td>"); ; break;
                            case "Bd_Ground": data.Append("<td>" + model.Bd_Ground + "</td>"); ; break;
                            case "UimNumber": data.Append("<td>" + model.UimNumber + "</td>"); ; break;
                            case "Number": data.Append("<td>" + model.Number + "</td>"); ; break;
                            case "ANumber": data.Append("<td>" + model.ANumber + "</td>"); ; break;
                            case "PNumber": data.Append("<td>" + model.PNumber + "</td>"); ; break;
                            case "NPNumber": data.Append("<td>" + (model.ANumber - model.PNumber) + "</td>"); ; break;                           
                        }
                    }
                    data.Append("</tr>");
                }
                data.Append("</table>");
            }
            #endregion

            string sw = ExcelHelper.ExcelTemplate(data.ToString());

            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
            // 写入到数据流
            return File(System.Text.Encoding.UTF8.GetBytes(sw.ToString()), "application/octet-stream", "预览总表_" + fileName + ".xls");

        }
    



        #endregion
    }

}
       




